<template>
<div>
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"   :disabled="formReadOnly"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="24">
            <el-form-item label="设备名称" prop="repairName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairName" placeholder="请填写设备名称"     ></el-input>
           </el-form-item>
        </el-col>
     <!--   <el-col :span="24">
            <el-form-item label="是否需要检修" prop="repairOrNot"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairOrNot" placeholder="请填写是否需要检修"     ></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12" >
            <el-form-item label="检修区域班长" prop="repairOrNot"
                :rules="[
                  {required: true, message:'请选择检修区域班长', trigger:'blur'}
                 ]">
                <user-select :limit='1' :value="inputForm.repairOrNot" @getValue='(value) => {inputForm.repairOrNot=value}'></user-select>
           </el-form-item>
            </el-col>
            <el-col :span="12" >
                <el-form-item label="检修工程师" prop="repairTime"
                    :rules="[
                      {required: true, message:'请选择检修区域班长', trigger:'blur'}
                     ]">
                    <user-select :limit='1' :value="inputForm.repairTime" @getValue='(value) => {inputForm.repairTime=value}'></user-select>
               </el-form-item>
                </el-col>
       <!-- <el-col :span="24">
            <el-form-item label="检修时间" prop="repairTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairTime" placeholder="请填写检修时间"     ></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="10">
          <el-form-item label="时间选择" prop="remarks"
              :rules="[
               ]">
            <el-date-picker
              v-model="inputForm.remarks"
              type="datetime"
              placeholder="选择日期时间"
              align="right"
              :picker-options="pickerOptions">
            </el-date-picker>
            </el-form-item>
            </el-col>
<!--        <el-col :span="24">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col> -->
        </el-row>
    </el-form>
</div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  export default {
    data () {
      return {
        pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick (picker) {
            picker.$emit('pick', new Date())
          }
        }, {
          text: '昨天',
          onClick (picker) {
            const date = new Date()
            date.setTime(date.getTime() - 3600 * 1000 * 24)
            picker.$emit('pick', date)
          }
        }, {
          text: '一周前',
          onClick (picker) {
            const date = new Date()
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', date)
          }
        }]
      },
        title: '',
        method: '',
        loading: false,
        inputForm: {
          id: '',
          repairName: this.outPutForm.repairName,
          repairOrNot: '',
          repairTime: '',
          remarks: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      },
      outPutForm: {
        repairName: '',
        remarks: ''
      }
    },
    components: {
      UserSelect
    },
    watch: {
      'businessId': {
        handler (newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      init (id) {
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/flowform/form/repairFlowTask/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.repairFlowTask)
              this.loading = false
            })
          })
        }
      },
      // 表单提交
      saveForm (callback) {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/flowform/form/repairFlowTask/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                callback(data.businessTable, data.businessId)
              }
            })
          }
        })
      }
    }
  }
</script>
